package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.dto.RoomDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    /**
     * 新增床位
     * @param bedDto 床位信息
     * @return 操作结果
     */
    //新增床位
    @PostMapping("/create")
    @ApiOperation(value = "新增床位", notes = "传入床位信息")
    public ResponseResult addBed(@ApiParam(value = "床位信息",readOnly = true) @RequestBody BedDto  bedDto) {
        int rows = bedService.addBed(bedDto);
        return toAjax(rows);
    }

    /**
     * 根据床位id查询床位
     * @param id id
     * @return 床位信息
     */
    //根据床位id查询床位
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据床位id查询床位", notes = "传入床位id")
    public ResponseResult<BedVo> readBedById(@ApiParam(value = "床位ID", required = true) @PathVariable("id")  Long id) {
        return success(bedService.getBedById(id));
    }

    /**
     * 修改床位
     * @param bedDto 床位信息
     * @return 操作结果
     */
    //修改床位
    @PutMapping("/update")
    @ApiOperation(value = "修改床位", notes = "传入床位信息")
    public ResponseResult updateBed(@ApiParam(value = "床位信息",readOnly = true) @RequestBody BedDto  bedDto) {
        int rows = bedService.updateBed(bedDto);
        return toAjax(rows);
    }


    /**
     * 删除床位
     * @param id 床位id
     * @return 操作结果
     */
    //删除床位
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位", notes = "传入床位id")
    public ResponseResult deleteBedById(@ApiParam(value = "床位ID", required = true) @PathVariable("id")  Long id) {
        int rows = bedService.deleteBedById(id);
        return toAjax(rows);
    }
}
